package com.capgemini.mulefocus.transformer;

import java.util.Date;

import org.mule.api.transformer.TransformerException;
import org.mule.example.hello.ChatString;
import org.mule.example.hello.NameString;
import org.mule.transformer.AbstractTransformer;
import org.mule.transformer.types.DataTypeFactory;

import com.capgemini.mulefocus.data.MongoDBPersistableObject;

/**
 * Transforms a name String to a String suitable for save in MongoDB. 
 * 
 * @author jcarlsen
 *
 */
public class NameStringToDBString extends AbstractTransformer {

	
	public NameStringToDBString()
    {
        super();
        this.registerSourceType(DataTypeFactory.create(NameString.class));
        this.setReturnDataType(DataTypeFactory.create(MongoDBPersistableObject.class));
    }
	@Override
	protected Object doTransform(Object src, String encoding)throws TransformerException {
		MongoDBPersistableObject mongoDBOPersistablebject = new MongoDBPersistableObject();
        NameString nameString = (NameString) src;
        mongoDBOPersistablebject.put("name", nameString.getName());
        mongoDBOPersistablebject.put("greeting", nameString.getGreeting());
        mongoDBOPersistablebject.put("timestamp", new Date());
        return mongoDBOPersistablebject;
	}

}
